package 实验7_2;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(5988);
            System.out.println("服务器已启动，等待客户端连接...");

            while (true) {
                Socket clientSocket = serverSocket.accept();
                System.out.println("客户端已连接");
                
                // 获取输入流和输出流
                BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(), true);
                
                // 读取客户端发送的三边数据
                double side1 = Double.parseDouble(reader.readLine());
                double side2 = Double.parseDouble(reader.readLine());
                double side3 = Double.parseDouble(reader.readLine()); 
                // 计算三角形面积
                double s = (side1 + side2 + side3) / 2;
                double area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
               
                // 发送面积给客户端
                writer.println(area);

                // 关闭连接
                clientSocket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
